/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			editorbase.h
  \date			Dec 2012
  \author		TNick

  \brief		Contains the definition for EditorBase class


*//*


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __EDITORBASE_INC__
#define __EDITORBASE_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<memtrack.h>
#include	<QString>
#include	<QObject>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  DEFINITIONS    --------------------------------------------------------- */

namespace	cpg		{

class	CpgDoc;

}

/*  DEFINITIONS    ========================================================= */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

class	QUrl;
class	QColor;
class	QFont;
class	QWidget;
class	QUndoStack;

/**
*	@brief
*/
class EditorBase			:	public MemTrack		{
	BBM_TRACK( EditorBase );

	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */


	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */

private:


	/**
	*	@brief	associated document
	*/
	cpg::CpgDoc *		document_;


	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

public:


//	/**
//	*	@brief	const = 0;
//	*/
//	EditorBase			( void ){}


//	/**
//	*	@brief	destructor;
//	*/
//	virtual				~EditorBase		( void ){}


	/**
	*	@brief	associated document
	*/
	cpg::CpgDoc *			document				( void ) const
	{ return document_; }


protected:


	/**
	*	@brief	set associated document
	*/
	void				setDocInternal				(
			cpg::CpgDoc * document )
	{ document_ = document; }





	/* ******************************************************************* */
	/** @name 	Interface methods                                         */
	/* ******************************************************************* */
	///@{


public:


	/**
	*	@brief	the name of this document
	*/
	virtual QString				documentName			( void ) = 0;


	/**
	*	@brief	the path of the file associated with this document
	*/
	virtual QString				filePath				( void ) = 0;


	/**
	*	@brief	the path of the file associated with this document
	*/
	virtual QWidget*			asWidget				( void ) = 0;


	/**
	*	@brief	undo-redo stack
	*/
	virtual QUndoStack*			undoStack				( void ) = 0;


public slots:


	/**
	*	@brief	save the content to given file or to a different file
	*
	*	As a result internally stored path changes. Modified flag is cleared.
	*/
	virtual bool				fileSave				( const QString & f = QString() ) = 0;



	/**
	*	@brief	initalises the view with a new, editable file
	*/
	virtual bool				fileNew					( void ) = 0;


	/**
	*	@brief	opens given local file
	*/
	virtual bool				fileOpen				(
			const QString & f,
			const QString & loc = QString()
			) = 0;



	/**
	*	@brief	opens given resource; the content is not editable
	*/
	virtual bool				openUrl					( const QUrl & url ) = 0;



	/**
	*	@brief	inserts the text at current cursor position
	*/
	virtual void				insertText				( const QString & text ) = 0;



	/**
	*	@brief	inserts the html content at current cursor position
	*/
	virtual void				insertHtml				( const QString & content = QString() ) = 0;


	/**
	*	@brief	inserts a table at current cursor position
	*/
	virtual void				insertTable				( void ) = 0;



	/**
	*	@brief	inserts a row or more at current cursor position
	*
	*	-1 is a special value and inserts a header row.
	*	0 will insert a number of rows equal to the number of
	*	selected rows.
	*/
	virtual void				insertTableRows			( int count = 1 ) = 0;


	/**
	*	@brief	removes a row or more at current cursor position
	*/
	virtual void				removeTableRows			( int count = 1 ) = 0;


	/**
	*	@brief	inserts a column or more at current cursor position
	*
	*	-1 will insert a single column as first column.
	*	0 will insert a number of columns equal to the number of
	*	selected columns.
	*/
	virtual void				insertTableCols			( int count = 1 ) = 0;


	/**
	*	@brief	removes a column or more at current cursor position
	*/
	virtual void				removeTableCols			( int count = 1 ) = 0;


	/**
	*	@brief	inserts an image at current cursor position
	*/
	virtual void				insertImage			( const QString & s_uri ) = 0;


	/**
	*	@brief	select all the content of the document
	*/
	virtual void				selectAll			( void ) = 0;



	/**
	*	@brief	delets currently selected text
	*/
	virtual void				deleteSel			( void ) = 0;



	/**
	*	@brief	cuts currently selected text
	*/
	virtual void				cut					( void ) = 0;



	/**
	*	@brief	copies currently selected text
	*/
	virtual void				copy				( void ) = 0;



	/**
	*	@brief	inserts the content of the clipboard
	*/
	virtual void				paste				( void ) = 0;


	/**
	*	@brief	undoes previous action
	*/
	virtual void				undo				( void ) = 0;



	/**
	*	@brief	redoes next action
	*/
	virtual void				redo				( void ) = 0;


	/**
	*	@brief	increases the zoom level
	*/
	virtual void				zoomIn				( qreal amount = 0.10 ) = 0;


	/**
	*	@brief	decreases the zoom level
	*/
	virtual void				zoomOut				( qreal amount = 0.10 ) = 0;


	/**
	*	@brief	change the zoom level
	*/
	virtual void				setZoom				( qreal value = 1 ) = 0;


	/**
	*	@brief	scroll the view to the named anchor
	*/
	virtual void				goToAnchor			( const QString & s_name ) = 0;


	/**
	*	@brief	changes the visibility of the find box
	*/
	virtual void				showFind			( bool b_visible ) = 0;


	/**
	*	@brief	find the text
	*/
	virtual void				findNext			( const QString & s_text ) = 0;


	/**
	*	@brief	find the text
	*/
	virtual void				findPrev			( const QString & s_text ) = 0;


	/**
	*	@brief	replace all occurances
	*/
	virtual void				replaceAll			( const QString & s_find, const QString & s_repl ) = 0;


	/**
	*	@brief	replace first occurance
	*/
	virtual void				replaceNext			( const QString & s_find, const QString & s_repl ) = 0;


	/**
	*	@brief	replace current occurance, if any
	*/
	virtual void				replaceOne			( const QString & s_find, const QString & s_repl ) = 0;




public:


	/**
	*	@brief	tell if there is an associated file or not (new or url) = 0;
	*/
	virtual bool				isUntitled				( void ) const = 0;



	/**
	*	@brief	tell if there are unsaved changes
	*/
	virtual bool				isModified				( void ) const = 0;


    /**
    *	@brief	color for filling containers
    */
    virtual QColor				fillColor				( void ) = 0;


	/**
	*	@brief	primary color
	*/
	virtual QColor				primColor				( void ) = 0;


	/**
	*	@brief	tell if the cursor is inside a table
	*/
	virtual bool				inTable					( void ) const = 0;


	/**
	*	@brief	set the read only flag
	*/
	virtual void			setReadOnly				( void ) = 0;



	/**
	*	@brief	reset the read only flag
	*/
	virtual void			resetReadOnly			( void ) = 0;



	/**
	*	@brief	tell if the document is read-only
	*/
	virtual bool			isReadOnly				( void ) const = 0;



	/**
	*	@brief	tell if the document has selection
	*/
	virtual bool			hasSelection			( void ) const = 0;


	/**
	*	@brief	tell if the document has selection
	*/
	virtual qreal			crtZoom					( void ) const = 0;


	/**
	*	@brief	tell if the document's find box is visible
	*/
	virtual bool			isFindVisible			( void ) const = 0;



	///@}
	/* ******************************************************************* */


	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//

};	/*	class EditorBase	*/

/*  CLASS    =============================================================== */
//
//
//
//
#endif // __EDITORBASE_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
